<template>
  <div>
    <div @click="changemenu" class="changemenu">|||</div>
    <el-menu background-color="#333744" text-color="#fff" active-text-color="#409eff" :unique-opened="true" :collapse="isCollapse" :collapse-transition="false" :router="true" :default-active="$route.path">
      <el-submenu :index="item.path" v-for="item in menus" :key="item.id">
        <template slot="title">
          <i :class="icon[item.id]"></i>
          <span>{{ item.authName }}</span>
        </template>
        <el-menu-item :index="'/' + subitem.path" v-for="subitem in item.children" :key="subitem.id">
          <template slot="title">
            <i class="el-icon-menu"></i>
            <span>{{ subitem.authName }}</span>
          </template>
        </el-menu-item>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
import { AsideMenu } from '../api/index.js'
import { mapState, mapMutations } from 'vuex'
export default {
  created() {
    this.getmenus()
  },
  data() {
    return {
      menus: {},
      icon: {
        125: 'iconfont icon-user',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao'
      }
    }
  },
  computed: {
    ...mapState({
      isCollapse: state => state.Home.isCollapse
    })
  },
  methods: {
    ...mapMutations(['changeCollapse']),
    async getmenus() {
      const { data: res } = await AsideMenu()
      if (res.meta.status !== 200) {
        this.$message({
          showClose: true,
          message: res.meta.msg,
          type: 'error'
        })
      } else {
        this.menus = res.data
        // console.log(this.menus)
      }
    },
    changemenu() {
      this.changeCollapse()
    }
  }
}
</script>

<style lang="less" scoped>
.iconfont {
  margin-right: 10px;
}
.el-menu {
  border: 0;
}
.changemenu {
  width: 100%;
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: white;
  text-align: center;
  letter-spacing: 0.2em;
}
</style>
